package de.unicornEntertainment.stundenplanapp.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import de.unicornEntertainment.stundenplanapp.R;
import de.unicornEntertainment.stundenplanapp.stundenplan.StundenplanDetailsActivity;

public class MyArrayAdapter_StundenplanDetails extends ArrayAdapter<HashMap<String, String>> {

	// Globale Deklaration
	private StundenplanDetailsActivity context;
	private HashMap<String, String> h;
	private int layoutRessource;
	private ArrayList<HashMap<String, String>> liste;
	
	
	// Konstruktor
	public MyArrayAdapter_StundenplanDetails(StundenplanDetailsActivity context, int layoutRessource, ArrayList<HashMap<String, String>> daten) {
		super(context, layoutRessource, daten);
		this.context = context;
		this.layoutRessource = layoutRessource;
		this.liste = daten;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View row = convertView;
        ViewHolder holder = null;
       
        if(row == null)
        {
            LayoutInflater inflater = context.getLayoutInflater();
            row = inflater.inflate(this.layoutRessource, parent, false);
           
            holder = new ViewHolder();
            holder.fach = (TextView) row.findViewById(R.id.stundenplan_gridview_fach);
            holder.lehrer = (TextView) row.findViewById(R.id.stundenplan_gridview_lehrer);
            holder.raum = (TextView) row.findViewById(R.id.stundenplan_gridview_raum);
            row.setTag(holder);
        }
        else
        {
            holder = (ViewHolder) row.getTag();
        }
       
        h = liste.get(position);
        
        holder.fach.setText(h.get("Fach").toString());
        holder.lehrer.setText(h.get("Kuerzel").toString());
        holder.raum.setText(h.get("Raumnummer").toString());
       
        return row;
    }
   
    static class ViewHolder
    {
        TextView raum;
        TextView lehrer;
        TextView stunde;
        TextView tag;
        TextView klasse;
        TextView fach;
    }
}
